package com.xd.center.http.builder;

import com.xd.center.http.annotation.HttpHeader;
import com.xd.center.http.annotation.HttpLine;
import com.xd.center.http.authentication.HttpAuth;
import lombok.Data;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data

public class MethodMetadata {
  //服务
  private Map<String, String> serverMap; //服务地址
  private String server; //服务地址key
  private HttpAuth httpAuth;
  //头
  private String[] headers;
  private boolean openAuth = Boolean.TRUE; //身份认证, true:开启(调用HttpAuth.auth()), false:关闭
  private HttpHeader.MediaType consumes = HttpHeader.MediaType.JSON; //请求
  private HttpHeader.MediaType produces = HttpHeader.MediaType.JSON; //响应
  //方法
  private String url;
  private String defaultUrl; //原始url
  private HttpLine.Method httpMethod = HttpLine.Method.POST;
  private boolean repeatInvoke;
  private String[] repeatInvokeField;
  //参数
  private Map<Integer, String> paramNameMap = new ConcurrentHashMap<>();
  //编码
  private HttpEncoder encoder;
  private HttpDecoder decoder;
  //请求
  //返回
  private Class<?> resultClass;
  private Type resultType;

  public Object encoder(Object object) {
    return encoder.encode(object, this);
  }

  public Object decoder(Object object) {
    return decoder.decoder(object, resultType, this);
  }
}

